﻿@{
    Layout = "~/_SiteLayout.cshtml";

    Business.Platform.WorkFlowComment bworkFlowComment = new Business.Platform.WorkFlowComment();
    Data.Model.WorkFlowComment workFlowComment = null;
    string id=Request.QueryString["id"];

    string member = string.Empty;
    string comment = string.Empty;
    string sort = string.Empty;

    bool isOneSelf = "1" == Request.QueryString["isoneself"];
    
    Guid commentID;
    if (id.IsGuid(out commentID))
    {
        workFlowComment = bworkFlowComment.Get(commentID);
        member = workFlowComment.MemberID;
        comment = workFlowComment.Comment;
        sort = workFlowComment.Sort.ToString();
    }
    string oldXML = workFlowComment.Serialize();
    Validation.RequireField("Comment");
    if(IsPost && Validation.IsValid())
    {
        member = isOneSelf ? Business.Platform.Users.PREFIX + Business.Platform.Users.CurrentUserID.ToString() : Request.Form["Member"];
        comment = Request.Form["Comment"];
        sort = Request.Form["Sort"];

        bool isAdd = false;
        if (workFlowComment == null)
        {
            isAdd = true;
            workFlowComment = new Data.Model.WorkFlowComment();
            workFlowComment.ID = Guid.NewGuid();
            workFlowComment.Type = isOneSelf ? 1 : 0;
        }

        workFlowComment.MemberID = member.IsNullOrEmpty() ? "" : member.Trim();
        workFlowComment.Comment = comment.IsNullOrEmpty() ? "" : comment.Trim();
        workFlowComment.Sort = sort.IsInt() ? sort.ToInt() : bworkFlowComment.GetManagerMaxSort();

        
        if(isAdd)
        {
            bworkFlowComment.Add(workFlowComment);
            Business.Platform.Log.Add("添加了流程意见", workFlowComment.Serialize(), Business.Platform.Log.Types.流程相关);
        }
        else
        {
            bworkFlowComment.Update(workFlowComment);
            Business.Platform.Log.Add("修改了流程意见", "修改前：" + oldXML + "修改后：" + workFlowComment.Serialize(), Business.Platform.Log.Types.流程相关);
        }
        bworkFlowComment.RefreshCache();
        <script type="text/javascript">
            new RoadUI.Window().reloadOpener();
            alert("保存成功!");
        </script>
    }
}

    <form method="post" action="">
    <br />
    <table cellpadding="0" cellspacing="1" border="0" width="99%" class="formtable">
    <tr>
        <th>
            意见：
        </th>
        <td>
            <textarea class="mytext" name="Comment" id="Comment" validate="empty" style="width:75%; height:60px;">@comment</textarea>
        </td>
    </tr>
    @if(!isOneSelf)
    {
    <tr>
        <th style="width: 80px;">
            使用成员：
        </th>
        <td>
            <input type="text" name="Member" id="Member" class="mymember" value="@member" style="width:60%" /> //为空表示给所有成员
        </td>
    </tr>
    }
    <tr>
        <th style="width: 80px;">
            序号：
        </th>
        <td>
            <input type="text" name="Sort" id="Sort" class="mytext" validate="canempty,int" value="@sort" />
        </td>
    </tr>
    </table>
    <div class="buttondiv">
        <input type="submit" value="确定保存" class="mybutton" onclick="return new RoadUI.Validate().validateForm(document.forms[0]);" />
        <input type="button" class="mybutton" value="取消关闭" style="margin-left: 5px;" onclick="new RoadUI.Window().close();" />
    </div>
    </form>